package org.hq.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices;
import org.springframework.security.oauth2.provider.code.InMemoryAuthorizationCodeServices;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore;

import java.util.Arrays;

/**
 * token 服务管理
 */
@Configuration
public class tokenService {
    @Autowired
   private ClientDetailsService clientDetailsService;

    @Autowired
    private TokenStore ts;
    //2.2.
    //令牌的管理服务令牌服务配置
    @Bean
    public AuthorizationServerTokenServices tokenService(){
        //创建默认的令牌服务
        DefaultTokenServices services = new DefaultTokenServices();
        //指定客户端详情配置
        services.setClientDetailsService(clientDetailsService);
        //支持产生刷新token
        services.setSupportRefreshToken(true);
        //token存储方式
        services.setTokenStore(ts);
        //令牌有效期 2小时
       services.setAccessTokenValiditySeconds(7200);
       //令牌刷新时间
       services.setRefreshTokenValiditySeconds(259200);
        return services;
    }
    @Bean
public AuthorizationCodeServices authorizationCodeService(){
        return new InMemoryAuthorizationCodeServices();
}
}
